package com.agritech.smartfarming.strategy;

import com.agritech.smartfarming.model.AgriculturalMachine;
import com.agritech.smartfarming.model.Position;

/**
 * 地形感知路径规划策略，考虑地形高度和障碍物
 */
public class TerrainAwarePathStrategy implements PathPlanningStrategy {
    @Override
    public void planPath(AgriculturalMachine machine, Position start, Position end) {
        System.out.println("【地形感知路径策略】为 " + machine.getName() + " 规划考虑地形的路径");
        System.out.println("起点: " + start);
        System.out.println("终点: " + end);
        
        // 模拟地形感知路径规划计算
        double directDistance = calculateDistance(start, end);
        // 地形感知路径通常比直线距离长
        double terrainAwareDistance = directDistance * 1.2;
        
        System.out.println("考虑地形因素后的路径距离: " + String.format("%.2f", terrainAwareDistance) + "米");
        System.out.println("预计行驶时间: " + String.format("%.1f", terrainAwareDistance / 4.0) + "分钟");
        System.out.println("已规避地形障碍和高度变化");
    }
    
    /**
     * 计算两点之间的距离（使用简化的欧几里得距离）
     */
    private double calculateDistance(Position start, Position end) {
        double latDiff = end.getLatitude() - start.getLatitude();
        double longDiff = end.getLongitude() - start.getLongitude();
        double altDiff = end.getAltitude() - start.getAltitude();
        
        // 简化计算，实际应考虑地球曲率
        return Math.sqrt(latDiff * latDiff + longDiff * longDiff + altDiff * altDiff) * 111000;
    }
} 